#include <iostream>
using namespace std;
typedef struct LNode 
{
    int data;
    struct LNode *next;
    LNode(int n) : data(n), next(nullptr){}
}LNode, *LinkList;

LNode *createCircularList(int n)
{
    LNode *head = new LNode(1);
    LNode *cur = head;
    for(int i = 2; i <= n; ++i)
    {
        cur->next = new LNode(i);
        cur = cur->next;
    }
    cur->next = head;
    return head;
}

void fun(int n, int m)
{
    LNode *head = createCircularList(n);
    LNode *pre = nullptr, *cur = head;

    while(cur->next != cur)
    {
        for(int i = 1; i < m; ++i)
        {
            pre = cur;
            cur = cur->next;
        }
        cout << cur->data << " ";
        pre->next = cur->next;
        delete cur;
        cur = pre->next;
    }
    cout << endl;
    cout << cur->data << endl;
    delete cur;
}
int main()
{
    int n, m; cin >> n >> m;
    fun(n, m);
    return 0;
}